package Practice_Enum;

/**
 * @author caesar
 * @date 2025/7/11
 * @Description:
 * @apiNote
 */
public enum Month {
    JANUARY("一月"),
    FEBRUARY("二月"),
    MARCH("三月"),
    APRIL("四月"),
    MAY("五月"),
    JUNE("六月"),
    JULY("七月"),
    AUGUST("八月"),
    SEPTEMBER("九月"),
    OCTOBER("十月"),
    NOVEMBER("十一月"),
    DECEMBER("十二月");

    private final String description;

    Month(String description) {
        this.description = description;
    }

    public String getDescription(){
        return description;
    }

    public static Month of(int value){
        if(value>=1 && value<=12){
            return Month.values()[value-1];
        }
        return null;
    }

    public int getValue(){
        return ordinal()+1;
    }

    public int length(boolean leapYear){
        switch(this){
            case FEBRUARY:
                return leapYear ? 29 : 28;
            case APRIL:
            case JUNE:
            case SEPTEMBER:
            case NOVEMBER:
                return 30;
            default:
                return 31;
        }
    }
}
